import { useRequest } from 'umi';
import { queryAllOpenRecordAPI } from './services';
import { createModel } from 'hox';
import { useState } from 'react';
import { DataNode } from 'antd/lib/tree';
type AreaListProps = DataNode & { code?: string };
interface HoxModelProps {
  areaList: AreaListProps[];
  selectedKeys: string[];
  currentCode: string;
}
function useHoxModel() {
  const [state, setState] = useState<HoxModelProps>({
    areaList: [],
    selectedKeys: [],
    currentCode: '',
  });
  const dispatch = (payload: Partial<HoxModelProps>) => {
    setState((pre) => ({ ...pre, ...payload }));
  };

  //开门记录
  const { run: getAllOpenRecord } = useRequest(queryAllOpenRecordAPI, {
    manual: true,
  });
  return {
    ...state,
    dispatch,
    //
    getAllOpenRecord,
  };
}
export default createModel(useHoxModel);
